package com.kaili.basic.controlle;


import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.pojo.dto.PickBoxManagedto;
import com.kaili.basic.pojo.entity.PickBoxManage;
import com.kaili.basic.pojo.vo.PickBoxManageVO;
import com.kaili.basic.service.PickBoxManageService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.util.LoginDetailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@ApiVersion(1)
@RestController
@RequestMapping("/{api_version}")
@Api(tags = "分拣盒管理", description = "分拣盒管理相关API")
public class SortingBoxController {


    @Autowired
    private PickBoxManageService pickBoxManageService;

    @PostMapping("/pickBox")
    @ApiOperation(value = "新增或修改", notes = "新增或修改分拣盒")
    public CommonStatus createPickBox(@RequestBody PickBoxManagedto pickBoxManagedto){

        PickBoxManage pickBoxManage = new PickBoxManage();
        pickBoxManage.setBoxName(pickBoxManagedto.getBoxName());
        pickBoxManage.setDepotId(pickBoxManagedto.getDepotId());
        pickBoxManage.setBoxNo(pickBoxManagedto.getBoxNo());
        pickBoxManage.setIsEnable(1);
        if (pickBoxManagedto.getBoxId() != null){
            /*修改*/
            pickBoxManage.setModifyBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
            pickBoxManage.setModifyTime(new Date());
            pickBoxManage.setBoxId(pickBoxManagedto.getBoxId());
            /*执行修改方法*/
            pickBoxManageService.updatePickBox(pickBoxManage);
            return CommonStatus.UPDATE_OK;
        }else{
            /*新增*/
            pickBoxManage.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
            pickBoxManage.setCreateTime(new Date());
            /*执行新增方法*/
            pickBoxManageService.createPickBox(pickBoxManage);
            return CommonStatus.ADD_OK;
        }


    }

    @GetMapping("/pickBox")
    @ApiOperation(value = "查询分拣盒", notes = "查询分拣盒")
    public Page<PickBoxManageVO> queryPickBox(@ModelAttribute PickBoxManagedto pickBoxManagedto){
        PickBoxManage pickBoxManage = new PickBoxManage();
        pickBoxManage.setBoxName(pickBoxManagedto.getBoxName());
        pickBoxManage.setDepotId(pickBoxManagedto.getDepotId());
        pickBoxManage.setBoxNo(pickBoxManagedto.getBoxNo());
        pickBoxManage.setPage(pickBoxManagedto.getPage());
        pickBoxManage.setPageSize(pickBoxManagedto.getPageSize());
        /*执行查询方法*/
        return pickBoxManageService.queryPickBox(new Page<PickBoxManageVO>(pickBoxManage.getPage(),pickBoxManage.getPageSize()),pickBoxManage);
    }

    @DeleteMapping("/pickBox/{id}")
    @ApiOperation(value = "删除分拣盒", notes = "删除分拣盒")
    public CommonStatus deleteBoxById(@PathVariable Integer id){
        /*执行删除方法*/
        if (id == null){}
        pickBoxManageService.deleteBoxById(id);
        return CommonStatus.DELETE_OK;
    }
}
